<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>任务拆分成多个子任务</title>
  </head>
  <body></body>
  <script>
    function hd() {
      for (let i = 0; i < 100000000; i++) {
        if (num <= 0) break;
        count += num--;
      }
      if (num > 0) {
        console.log(num);
        //利用定时器来拆分一个大数字num,分段计算，先执行后续的同步代码，输出houdunren
        setTimeout(hd);
      } else {
        console.log(count);
      }
    }
    let num = 987654321;
    let count = 0;
    hd();
    console.log("houdunren");
  </script>
</html>
